﻿using System.ComponentModel.Composition;
using System.Net;
using System.Net.Http;

namespace Neo4jConnect.Rest
{  
    [Export(typeof(ITraversalService))]
    public class HttpClientTraversalService : ITraversalService
    {
        private readonly HttpClient client;

        public HttpClientTraversalService(HttpClient client)
        {
            this.client = client;
        }

        public string Traverse(ulong nodeId, TraversalReturnType returnType, string nodeData)
        {
            return client
                .Post(string.Format("node/{0}/traverse/{1}", nodeId, returnType.GetDescription()), new StringContent(nodeData))
                .EnsureStatusCode(HttpStatusCode.OK)
                .Content.ReadAsString();
        }
    }
}
